cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(recipe-13-01 LANGUAGES CXX)
add_executable(arch-dependent arch_dependent.cpp)

if (CMAKE_SIZEOF_VOID_P EQUAL 8) # 64-bit
    target_compile_definitions(arch-dependent PUBLIC "IS_64_BIT_ARCH")
    message(STATUS "Target architecture is 64 bits (void* size is 8 bytes)")
else() # 32-bit
    target_compile_definitions(arch-dependent PUBLIC "IS_32_BIT_ARCH")
    message(STATUS "Target architecture is 32 bits (void* size is not 8 bytes)")
endif()

# CMAKE_HOST_SYSTEM_PROCESSOR 变量包含主机 CPU 的标识符。
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i386")
    message(STATUS "Host processor architecture detected: i386")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "i686")
    message(STATUS "Host processor architecture detected: i686")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
    message(STATUS "Host processor architecture detected: x86_64")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "AMD64") # 某些系统可能使用 AMD64
    message(STATUS "Host processor architecture detected: AMD64")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") # ARM 64位
    message(STATUS "Host processor architecture detected: aarch64")
# 可以根据需要添加更多 elseif 分支来检测其他常见的体系结构，如 armv7l, ppc64 等。
else()
    message(STATUS "Host processor architecture is unknown: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()

target_compile_definitions(arch-dependent
    PUBLIC "ARCHITECTURE=${CMAKE_HOST_SYSTEM_PROCESSOR}"
    )
